#ifndef __DANIEL_BASESHM_H__
#define __DANIEL_BASESHM_H__
#include <string>
#include <memory>
//提供共享内存IPC(Inter Process Communacation)的封装
namespace daniel
{
    class BaseShm
    {
    public:
        using ptr=std::shared_ptr<BaseShm>;
        //根据ID值，获得已经创建完毕的共享内存
        BaseShm(int32_t shmKey);
        BaseShm(const std::string& path);
        //创建共享内存
        BaseShm(int32_t shmKey, int32_t size);
        BaseShm(const std::string& path, int32_t size);
        ~BaseShm();
        //attach到进程、从进程detach，销毁；
        void* attachToProcess();
        void detachFromProcess();
        int32_t getShmid() const;
        void* getShmStart() const;
        void destroyShm();
        //写入数据，读取数据，对共享内存临界区的控制
    private:
        BaseShm(const BaseShm&)=delete;
        BaseShm operator=(const BaseShm&)=delete;
    private:
        const int32_t c_proID='X';
        int32_t m_shmId;
        void* m_shmaddr;
    };
}

#endif
